/*
 * 修改用户交易
 * 参数   交易码：trancode=1013
 *  liuguangshuai@gmail.com
 * @系统名称：定制化辅助生成制造系统
 */

package org.ccams.tran;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.ccams.domain.User;

public class Tran1013 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String userName = (String) request.getParameter("userName");
		String loginName = (String) request.getParameter("loginName");
		String passWord = (String) request.getParameter("passWord");
		String email = (String) request.getParameter("email");
		String rId = (String) request.getParameter("RId");
		String id = (String) request.getParameter("id");
		rId = (rId != null) ? rId : "1";
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		
		User u = new User();
		u.setEmail(email);
		u.setLoginName(loginName);
		u.setPassWord(passWord);
		u.setRId(Long.parseLong(rId));
		u.setUserName(userName);
		u.setId(Integer.parseInt(id));
		int i = getCcamsService().getUserDao().updateUser(u);
		if (i == 1) {
			success = true;
			message = "用户修改成功";
		} else {
			success = false;
			message = "用户修改失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
